package com.fitbet.admin.web.controller.bonus;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.entity.page.Page;
import com.demo2do.core.web.interceptor.MenuSetting;
import com.demo2do.core.web.utils.WebUtils;
import com.fitbet.admin.entity.search.bonus.UserWithdrawalSearch;
import com.fitbet.admin.service.bonus.WithdrawalRecordsService;
import com.fitbet.entity.user.UserWithdrawal;

/**
 * 提现记录
 * @author sjh
 *
 */
@Controller
@MenuSetting("menu-bonus")
@RequestMapping("/withdrawal-records")
public class WithdrawalRecordsController {
	
    @Autowired
    private WithdrawalRecordsService betService;
    
	/**
	 * 
	 * @return
	 */
	@RequestMapping(value = "", method = RequestMethod.GET)
	@MenuSetting("submenu-withdrawal-records-list")
	public ModelAndView list(Page page) {
		
		ModelAndView modelAndView = new ModelAndView("bonus/withdrawal-records/withdrawal-records-list");
		
		int totals = betService.count(UserWithdrawal.class);
		
		if (totals >0 ) {
            
		    List<UserWithdrawal> userWithdrawals = betService.listByPage(UserWithdrawal.class, page.with(totals));
		    modelAndView.addObject("userWithdrawals", userWithdrawals);
		    modelAndView.addObject("page", page);
		    
        }
		
		return modelAndView;
	}

	@RequestMapping(value = "/search", method = RequestMethod.GET)
    public String search() {
        return "bonus/withdrawal-records/withdrawal-records-search";
    }
    
    /**
     * 
     * @param search
     * @param page
     * @param request
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET, params = "filter")
    @MenuSetting("submenu-withdrawal-records-list")
    public ModelAndView onSearch(UserWithdrawalSearch search, Page page, HttpServletRequest request) {
        
        ModelAndView modelAndView = new ModelAndView("bonus/withdrawal-records/withdrawal-records-list");
        
        int totals = betService.count(UserWithdrawal.class, search.getPreparedFilter(false));
        if (totals > 0) {
            
            List<UserWithdrawal> userWithdrawals = betService.search(UserWithdrawal.class, search, page.with(totals));
            modelAndView.addObject("userWithdrawals", userWithdrawals);
            
            modelAndView.addObject("page", page);
            modelAndView.addObject("queryString", WebUtils.extractQueryString(request, "filter","page"));
            
        }
        
        return modelAndView;
        
    }
	
}
